@php
    $user = Auth::user();
    $role = $user->roles()->get();
	$role_id = $user->cur_role_id;
	$role_name = $role->where('id', $role_id)->first();
    $role_name = $role_name?$role_name->rolename:'';
	$actions = $user->getUserOper($role_id);
    $actions = implode(",", $actions);

	if(!$role_name){
		$role_id = !empty($role[0]['id'])?$role[0]['id']:0;
		$role_name = !empty($role[0]['rolename'])?$role[0]['rolename']:'';
	}
    //父页面的role_id要设置为全局变量，否则子页面获取不到


@endphp

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>华理大附小-教师发展平台</title>
		<!-- 依 赖 样 式 -->
		<link rel="stylesheet" href="{{ asset('lib/Pear-Admin-Layui-next/component/pear/css/pear.css') }}" />
		<!-- 加 载 样 式 -->
		<link rel="stylesheet" href="{{ asset('lib/Pear-Admin-Layui-next/admin/css/loader.css') }}" />
		<!-- 布 局 样 式 -->
		<link rel="stylesheet" href="{{ asset('lib/Pear-Admin-Layui-next/admin/css/admin.css') }}" />
		<script>
			var app_env ="{{env('APP_ENV')}}";
			sessionStorage.setItem('app_env', app_env); //当前环境
		</script>
		<!-- 依 赖 脚 本 -->
		<script src="{{ asset('lib/Pear-Admin-Layui-next/component/layui/layui.js')}}"></script>
		<script src="{{ asset('lib/Pear-Admin-Layui-next/component/pear/pear.js')}}"></script>
    	<script type="text/javascript" src="{{ asset('js/jquery-3.6.0.min.js').'?'.rand() }}"></script>
    	<script type="text/javascript" src="{{ asset('js/common.js').'?'.rand() }}"></script>
    	<script type="text/javascript" src="{{ asset('js/api.js').'?'.rand() }}"></script>
		<!-- 框 架 初 始 化 -->
		<script>
			layui.use(['admin','jquery','popup','yaml'], function() {
				var $ = layui.jquery;
				var admin = layui.admin;
				var popup = layui.popup;
				var yaml = layui.yaml;
				admin.setConfigType("yml");
				admin.setConfigPath("/lib/Pear-Admin-Layui-next/config/pear.config.yml");

				var role_id = "{{$role_id}}";
				if(role_id){
					admin.render(undefined,role_id); //切换管理员需修改此方法的源码（课程地图有修改）
				}else{
					admin.render();
				}

				//设置全局role_id
				sessionStorage.setItem('role_id', '{{$role_id}}');

				//切换角色权限
				$('.change-role').click(function(){
					var role_id = $(this).attr('role_id');
					var role_name = $(this).text();
					setUserCurRole({role_id: role_id},function (res) {
						if (res.code === 1){
							window.location.href = '';
						}
					});
				});

				$(function(){
					sessionStorage.setItem('actions', '{{ $actions }}');
				});
			});
		</script>
		<style>
			.pear-admin .layui-logo{
				height: 61px !important;
			}
			.dbycd a{
				color:dimgray !important;
			}
		</style>
	</head>

	<!-- 结 构 代 码 -->
	<body class="layui-layout-body pear-admin">
		<!-- 布 局 框 架 -->
		<div class="layui-layout layui-layout-admin">
			<!-- 顶 部 样 式 -->
			<div class="layui-header">
				<!-- 菜 单 顶 部 -->
				<div class="layui-logo">
					<!-- 图 标 -->
        			<img class="logo">
					<!-- 标 题 -->
					<span class="title"></span>
				</div>
				<!-- 顶 部 左 侧 功 能 -->
				<ul class="layui-nav layui-layout-left">
					<li class="collapse layui-nav-item"><a href="#" class="layui-icon layui-icon-shrink-right"></a></li>
					<li class="refresh layui-nav-item"><a href="#" class="layui-icon layui-icon-refresh-1" loading = 600></a></li>
				</ul>
				<!-- 多 系 统 菜 单 -->
				<div id="control" class="layui-layout-control"></div>
				<!-- 顶 部 右 侧 菜 单 -->
				<ul class="layui-nav layui-layout-right dbycd" >
					<!-- <li class="layui-nav-item "><a href="/" >返回管理首页</a></li><span style="color:dimgray" >|</span>
					<li class="layui-nav-item "><a href="apps/index" >返回前台首页</a></li><span style="color:dimgray" >|</span> -->
					<li class="layui-nav-item ">
						<!-- 头 像 -->
						<a class="layui-icon" href="javascript:;">{{$role_name}}<i class="layui-icon layui-icon-triangle-d" ></i></a>
						<!-- 功 能 菜 单 -->
						<dl class="layui-nav-child">
							@foreach($role as $v)
							<dd><a  href="javascript:;" class="change-role" role_id="{{$v['id']}}" >{{$v['rolename']}}</a></dd>
							@endforeach
						</dl>
					</li>
					<!-- <span style="color:dimgray" >|</span> -->
					<li class="layui-nav-item "></li>
					<li class="layui-nav-item">
						<!-- 头 像 -->
						<a class="layui-icon" href="javascript:;">{{$user->nickname}}<i class="layui-icon layui-icon-triangle-d" ></i> </a>
						<!-- 功 能 菜 单 -->
						<dl class="layui-nav-child">
							<dd><a href="/uaclogout" class="logout">退出登录</a></dd>
						</dl>
					</li>
					<!-- 主 题 配 置 -->
					<li class="layui-nav-item setting"><a href="#" class="layui-icon layui-icon-more-vertical"></a></li>
				</ul>
			</div>
			<!-- 侧 边 区 域 -->
			<div class="layui-side layui-bg-black">
				<!-- 菜 单 顶 部 -->
				<div class="layui-logo">
					<!-- 图 标 -->
					<img class="logo"></img>
					<!-- 标 题 -->
					<span class="title"></span>
				</div>
				<!-- 菜 单 内 容 -->
				<div class="layui-side-scroll">
					<div id="sideMenu"></div>
				</div>
			</div>
			<!-- 视 图 页 面 -->
			<div class="layui-body">
				<!-- 内 容 页 面 -->
				<div id="content"></div>
			</div>
			<!-- 遮 盖 层 -->
			<div class="pear-cover"></div>
			<!-- 加 载 动 画 -->
			<!-- <div class="loader-main"> -->
				<!-- 动 画 对 象 -->
				<!-- <div class="loader"></div>
			</div> -->
		</div>
		<!-- 移 动 端 便 捷 操 作 -->
		<div class="pear-collasped-pe collaspe">
			<a href="#" class="layui-icon layui-icon-shrink-right"></a>
		</div>
	</body>
</html>
